package bank;

import java.io.IOException;
import java.rmi.RemoteException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import beans.PageBean;

public class BankStatus extends HttpServlet
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void init()
	{
		System.out.println("BankStatus.init()");
	}
	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		System.out.println("BankStatus.doGet()");
		
		UberClass uberclass = new UberClass(request, response);
		PageBean pb = new PageBean("medewerker/BankStatus.jsp");
		request.setAttribute("page", pb);
		processStatus(uberclass);
		
		uberclass.startOutput();
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		System.out.println("BankStatus.doPost()");
		
		UberClass uberclass = new UberClass(request, response);
		
		boolean open;
		String status = request.getParameter( "status" );
		if(status.equals( "Open de bank" ))
			open = true;
		else
			open = false;
		uberclass.getManager().setOpen(open);
		
		PageBean pb = new PageBean("medewerker/BankStatus.jsp");
		request.setAttribute("page", pb);
		processStatus(uberclass);
		
		uberclass.startOutput();
	}
	
	public void processStatus(UberClass u)
	{
		String status;
		status = u.getManager().getStatus();
		u.setVar("status", status);
		String open = "";
		if(status.matches("(.*)open(.*)"))
			open = "true";
		else
			open = "false";
		u.setVar("open", open);
	}
}
